package com.ruoyi.caiwu.params;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.ruoyi.caiwu.enums.UserType;
import com.ruoyi.caiwu.utils.WebUtils;
import com.ruoyi.system.api.domain.SysUser;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

@lombok.Getter
@lombok.Setter
@lombok.ToString
public class BaseParam {
	protected UserType loginUserType;
	protected long loginUserId;
	
	public BaseParam() {
		this.loginUserType = WebUtils.getUserType();
		if (this.loginUserType == UserType.B_USER) {
			SysUser user = (SysUser)SecurityUtils.getSubject().getPrincipal();
			if (user != null) {
				this.loginUserId = user.getUserId();
			}
		}
		else if (this.loginUserType == UserType.C_USER) {
			String userId = (String)RequestContextHolder.getRequestAttributes().getAttribute("LOGIN_USER_KEY", RequestAttributes.SCOPE_REQUEST);
			if (StringUtils.isNotBlank(userId)) {
				this.loginUserId = Long.valueOf(userId);
			}
		}
	}
	
	protected BaseParam(UserType userType) {
		this.loginUserType = userType;
	}
}
